package cn.leyou.controller;

import cn.leyou.Item;
import cn.leyou.item.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 21195
 * @version v1.0
 * @package cn.leyou.controller
 * @description:
 * @date 2019/6/22 21:43
 **/
@RestController
public class IntemController {
    @Autowired
    private ItemService itemService;

    @PostMapping("item")
    public ResponseEntity<Item> saveItem(Item item){
        //如果价格为空，则抛出异常，返回400状态码，请求参数有误
        if (item.getPrice()==null){
            throw new RuntimeException("价格不能为空");
        }
        Item result = itemService.saveItem(item);
        return ResponseEntity.ok(result);
    }
}
